/*
 * (C) 2005 National Australia Bank
 *
 * [All rights reserved]. This product and related documentation are protected
 * by copyright restricting its use, copying, distribution, and decompilation.
 * No part of this product or related documentation may be reproduced in any
 * form by any means without prior written authorization of
 * National Australia Bank. Unless otherwise arranged, third parties may not
 * have access to this product or related documents.
 */
package au.com.evoCoach.controller;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import au.com.evoCoach.domain.Coach;
import au.com.evoCoach.form.TeamSubmissionForm;
import au.com.evoCoach.service.PlayerForRoundService;
import au.com.evoCoach.service.TeamService;

@Controller
public class TeamSubmission {
	
	private TeamService teamService;
	private PlayerForRoundService playerForRoundService;
	
	@Autowired
	public TeamSubmission(TeamService teamService, PlayerForRoundService playerForRoundService) {
		this.teamService = teamService;
		this.playerForRoundService = playerForRoundService;
	}
	
	@RequestMapping("/displayTeamSubmission.action")
	public String execute(Map model, HttpSession session) throws Exception {
		
		Coach coach = (Coach) session.getAttribute("loggedInCoach");
		model.put("teamDetails", teamService.getTeamDetails(coach.getTeam(), false));
		model.put("coach", coach);

		model.put("teamSubmissionForm", teamService.getTeamSubmissionForm(coach.getTeam()));
		
		return "teamSubmission";
	}
	
    @RequestMapping("/submitTeamSubmission.action")
    public String submitTeamSubmission(TeamSubmissionForm teamSubmissionForm, HttpSession session, Map model) {
        Coach coach = (Coach) session.getAttribute("loggedInCoach");
        
        playerForRoundService.submitTeamForRound(teamSubmissionForm, coach.getTeam());
        
        return "redirect:displayHomePage.action";
    }	

}
